package com.zyw.common.util;


import java.math.BigDecimal;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.Date;


public class DateUtil {


	public static String FORMAT_24HOUR="yyyy-MM-dd HH:mm:ss";
	public static String FORMAT_24HOUR_LONG="yyyyMMddHHmmss";
	public static String FORMAT_DATE="yyyy-MM-dd";
    /**
     * 获取当前时间 Timestamp 对象
     *
     * @return
     */
    public static Timestamp now() {
        return new Timestamp(System.currentTimeMillis());
    }

    /**
     * 获取当前时间 Timestamp 对象
     *
     * @return
     */
    public static Date nowDate() {
        return new Date();
    }
    
    
   /**
    * 将时间戳转换为24小时日期时间格式字符串
    * @param timeStamp
    * @return
    */
   public static String dateToStamp(String timeStamp){
       String res=null;
       try {
           SimpleDateFormat simpleDateFormat = new SimpleDateFormat(FORMAT_24HOUR);
           Date date = simpleDateFormat.parse(timeStamp);
           long ts = date.getTime();
           res = String.valueOf(ts);
		} catch (Exception e) {
			// TODO: handle exception
		}
       return res;
   }
   
   /**
    * 将去除符号的日期时间字符串转换为日期
    * @param dateTimeLong
    * @return
    */
   public static Date strLongToDate(String dateTimeLong) {
	   Date date =null;
       try {
           SimpleDateFormat simpleDateFormat = new SimpleDateFormat(FORMAT_24HOUR_LONG);
           date= simpleDateFormat.parse(dateTimeLong);
		} catch (Exception e) {
			// TODO: handle exception
		}
       return date;
   }
   
   /**
    * 将日期(格式:yyyy-MM-dd HH:mm:ss)字符串转换为Date
    * @param dateTimeLong
    * @return
    */
   public static Date strToDate(String dateTime) {
	   Date date =null;
       try {
           SimpleDateFormat simpleDateFormat = new SimpleDateFormat(FORMAT_24HOUR);
           date= simpleDateFormat.parse(dateTime);
		} catch (Exception e) {
			// TODO: handle exception
		}
       return date;
   }
   
   
   /**
    * 将日期转换为yyyyMMddHHmmss格式字符串
    * @param date
    * @return
    */
   public static String dateToDateTimeLongStr(Date date) {
	   String dateTimeStr=null;
       try {
           SimpleDateFormat simpleDateFormat = new SimpleDateFormat(FORMAT_24HOUR_LONG);
           dateTimeStr= simpleDateFormat.format(date);
		} catch (Exception e) {
			// TODO: handle exception
		}
       return dateTimeStr;
   }
   
   /**
    * 将日期转换为24小时日期时间格式字符串
    * @param date
    * @return
    */
   public static String dateToDateTimeStr(Date date) {
	   String dateTimeStr=null;
       try {
           SimpleDateFormat simpleDateFormat = new SimpleDateFormat(FORMAT_24HOUR);
           dateTimeStr= simpleDateFormat.format(date);
		} catch (Exception e) {
			// TODO: handle exception
		}
       return dateTimeStr;
   }
   
   /**
    * 将日期转换为yyyy-MM-dd格式字符串
    * @param date
    * @return
    */
   public static String dateToDateStr(Date date) {
	   String dateTimeStr=null;
       try {
           SimpleDateFormat simpleDateFormat = new SimpleDateFormat(FORMAT_DATE);
           dateTimeStr= simpleDateFormat.format(date);
		} catch (Exception e) {
			// TODO: handle exception
		}
       return dateTimeStr;
   }
   
   
   public static void main(String[] args) {
	   
	   System.out.println(new BigDecimal("20180301152617").divide(new BigDecimal("100")).toPlainString());
	   String txnTime="20180301152617";
	   Date date=strLongToDate(txnTime);
	   System.out.println(dateToDateTimeStr(date));
	   /*
	   System.out.println(new Date().getTime());
	   System.out.println(dateToStamp("20180301152617"));
	   String txnTime="20180301152617";
	   System.out.println(txnTime.substring(0, 4)+"-"+txnTime.substring(4,6)+"-"+txnTime.substring(6,8)+" "+txnTime.substring(8,10)+":"+txnTime.substring(10,12)+":"+txnTime.substring(12,14));
	   **/
   }
}
